/*
 * @Description  : 路由配置
 * @Author       : Keyman
 * @Date         : 2025-10-29 11:00:47
 * @LastEditors  : Keyman
 * @LastEditTime : 2025-11-21 00:41:42
 */

import { lazy } from "react";
import RequireAuth from "../utils/RequireAuth";

// 使用 lazy 加载页面，提高首屏加载速度
const Home = lazy(() => import("../page/home/index"));
const Login = lazy(() => import("../page/login/index"));
const NotFound = lazy(() => import("../page/404/index"));

import { type RouteObject } from "react-router-dom";

// const router = createBrowserRouter([
//   {
//     path: "/",
//     element: (
//       <RequireAuth allowed={true} redirectTo="/login">
//         <Home />
//       </RequireAuth>
//     ),
//   },
//   {
//     path: "/login",
//     element: (
//       <RequireAuth allowed={false} redirectTo="/">
//         <Login />
//       </RequireAuth>
//     ),
//   },
//   {
//     path: "*",
//     element: <NotFound />,
//   },
// ]);

const routerForm: RouteObject[] = [
  {
    path: "/",
    element: (
      <RequireAuth allowed={true} redirectTo="/login">
        <Home />
      </RequireAuth>
    ),
  },
  {
    path: "/login",
    element: (
      <RequireAuth allowed={false} redirectTo="/dashboard">
        <Login />
      </RequireAuth>
    ),
  },
  {
    path: "*",
    element: <NotFound />,
  },
];

export default routerForm;
